package com.rgs.rabbitmq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


/**
 * @program: com-rgs-parent
 * @description: 路由direct模式
 * @author: Mr.Ren
 * @create: 2023-01-06 10:22
 **/
@Configuration
public class DirectRabbitConfig {

    /**
     * 创建队列
     *
     * @return
     */
    @Bean
    public Queue rabbitmqDemoDirectQueue() {
        return new Queue(RabbitMQConfig.RABBITMQ_DEMO_QUEUE, true, false, false);
    }

    /**
     * 设置交换机
     *
     * @return
     */
    @Bean
    public DirectExchange rabbitmqDemoDirectExchange() {
        return new DirectExchange(RabbitMQConfig.RABBITMQ_DEMO_DIRECT_EXCHANGE, true, false);
    }

    /**
     * 队列绑定交换机
     *
     * @return
     */
    @Bean
    public Binding bindingDirect() {
        return BindingBuilder
                .bind(rabbitmqDemoDirectQueue())
                .to(rabbitmqDemoDirectExchange())
                .with(RabbitMQConfig.RABBITMQ_DEMO_DIRECT_ROUTING);
    }

}
